home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / win_a_d / aspdll.zip / RANDINT.C < prev    next >
C/C++ Source or Header  |  1992-07-10  |  3KB  |  65 lines

  1. /***********************************************************************
  2.  *                                                                     *
  3.  * RANDINT                                                             *
  4.  *                                                                     *
  5.  * Sample DLL for use with Procomm Plus for Windows.                   *
  6.  *                                                                     *
  7.  * This DLL module allows a user to generate a random number to be     *
  8.  * used within the Aspect language.                                    *
  9.  *                                                                     *
  10.  ***********************************************************************/
  11. /***********************************************************************
  12.  *                                                                     *
  13.  * Code Disclaimer                                                     *
  14.  *                                                                     *
  15.  * This sample is provided as a service to you.  DATASTORM does not in *
  16.  * any way warrant the source code, nor do we commit to any support on *
  17.  * this sample file.                                                   *
  18.  *                                                                     *
  19.  ***********************************************************************/
  20.  
  21. #include <windows.h>
  22. #include <stdlib.h>
  23.  
  24. #define IntegerType 1
  25.  
  26. int FAR PASCAL LibMain( HANDLE, WORD, WORD, LPSTR );
  27. int FAR PASCAL RandomInt( HWND, HANDLE, void far * far *, LPBYTE, int );
  28. int FAR PASCAL WEP( int );
  29.  
  30. HANDLE hInst;
  31.  
  32. int FAR PASCAL LibMain( HANDLE hInstance, WORD wDataSeg, WORD cbHeapSize,
  33.   LPSTR lpszCmdLine )
  34. {
  35.   if (cbHeapSize)
  36.     UnlockData(0);    /* make the data segment moveable */
  37.     hInst = hInstance;
  38.     return(TRUE);
  39. }
  40.  
  41. int FAR PASCAL RandomInt( HWND PWWnd, HANDLE PWInst,
  42.     void far * far *vdatptr, LPBYTE vtypeptr, int argcnt )
  43. {
  44.     if ( argcnt < 1 )                     /* at least one argument? */
  45.         return( FALSE );                    /* if not, return FAILURE */
  46.     if ( vtypeptr[0] != IntegerType )     /* is first arg an integer? */
  47.         return( FALSE );                    /* if not, return FAILURE */
  48.     if ( argcnt > 1 ) {                   /* more arguments? */
  49.         if ( vtypeptr[1] != IntegerType )   /* is second argument an integer? */
  50.             return( FALSE );                  /* if not, return FAILURE */
  51.         srand( *(int far *)vdatptr[0] );    /* seed the generator with arg */
  52.         *(int far *)vdatptr[1] = rand();    /* get a random number */
  53.     }
  54.     else {
  55.         srand( (unsigned)GetCurrentTime() );    /* seed the generator with time */
  56.         *(int far *)vdatptr[0] = rand();    /* get a random number */
  57.     }
  58.     return( TRUE );                       /* return SUCCESS to Aspect */
  59. }
  60.  
  61. int FAR PASCAL WEP( int bSystemExit )
  62. {
  63.     return(TRUE);
  64. }
  65.